home *** CD-ROM | disk | FTP | other *** search
- Path: ts1-000.jaxnet.com!user
- From: garyg@jax.jaxnet.com (Gary M. Greenberg)
- Newsgroups: comp.lang.c
- Subject: Re: Newbie needs help w/ recursion
- Date: 24 Mar 1996 17:37:23 GMT
- Organization: Southeast Network Services, Inc.
- Message-ID: <garyg-2403961228170001@ts1-000.jaxnet.com>
- References: <4ikq6p$io1@impsets.dash.com> <garyg-2403961218500001@ts1-000.jaxnet.com>
- NNTP-Posting-Host: ts1-000.jaxnet.com
-
- He inanely wrote:
-
- > In article <4ikq6p$io1@impsets.dash.com>, Jim Bosshardt <jbossha@dash.com>
- > wrote:
- >
- > > Hi, I am new and am about to pull my hair out over the supposedly simple
- > > recursion problem I have. The function is to take a number and raise it
- > > to a neg or pos power and return the value to main(). I need to take
- > > the following and make it a recursive function...
- > >
- > [snip]
- >
- > When I was very new to C programming, I wrote this one to solve the
- > problem in the Waite Group's New C Primer Plus. This sounds familiar.
- > I've not revisited the code but here was my function ...
- >
- [SNIP <Cancel issued on posting, but likely not effective>]
-
- Clearly non-recursive solution posted; sorry.
-
- I grabbed the wrong 'clipboard'
-
- the recursive solution that I used was:
-
- /* ïïïïïïïïï r_do_power function ïïïïïïïï */
- double r_do_power (double x,int y)
- {
- double r_pow=x;
- if(x==0)
- r_pow=0;
- if(x!=0 && y==0)
- r_pow=1;
- if((x>0 || x<0) && y>0)
- r_pow = r_pow * r_do_power(x,y - 1);
-
- if((x>0 || x<0) && y < 0)
- r_pow = 1/r_pow * 1/r_do_power(1/x,y + 1);
-
- return r_pow;
- }
- /*** WARNING *** WARNING *** WARNING ***/
- Be advised that recursive calls for even rather small powers often result
- in crashes due to stack overload.
- /*** caveat emptor ***/
-
- C'ya,
-
- gary /* the Sorcerer's Apprentice */
- http:/jax.jaxnet.com/~garyg/main_page.html
-
- Free Speech in America murdered by the Communications Decency Act.
- (((U.S. Congress && Executive) == (Collective Moron)) == 1)
-